﻿Create proc proc_insertDonViTinh
(
 @STTHangHoa int,
 @TenDonViTinh nvarchar(50),
 @LaMacDinh bit,
 @GiaTriQuiDoi float
)
as 
 insert into DonViTinh values(@STTHangHoa,@TenDonViTinh,@LaMacDinh,@GiaTriQuiDoi)
 
Create proc proc_insertHangHoa
(
 @TenHangHoa nvarchar(50),
 @SoLuongTonKho float,
 @TenDonViTinh nvarchar(50)
)
as
begin
 declare @STTHangHoa int
 insert into HangHoa values(@TenHangHoa,@SoLuongTonKho)
 select @STTHangHoa = STT from HangHoa where TenHangHoa = @TenHangHoa
 exec proc_insertDonViTinh @STTHangHoa,@TenDonViTinh,1,1
end

Create proc proc_insertDonGiaNhap
(
 @STTHangHoa int,
 @DonGiaNhap int,
 @ThoiGian DateTime
)
as
 insert into DonGiaNhap values(@STTHangHoa,@DonGiaNhap,@ThoiGian)

Create proc proc_insertNhapHang
(
 @STTHangHoa int,
 @SoLuongNhap float,
 @TenDonViTinh nvarchar(50),
 @DonGiaNhap float,
 @ThoiGian Datetime
)
as
 insert into NhapHang values(@SoLuongNhap,@SoLuongNhap,@TenDonViTinh,@DonGiaNhap,@TenDonViTinh)

Create proc proc_insertMenu
(
 @TenThucUong nvarchar(50),
 @DonGia	int
)
as
 insert into Menu values(@TenThucUong,@DonGia)

Create proc proc_insertCongThucMenu
(
 @STTMenu int,
 @STTHangHoa int,
 @SoLuong float,
 @TenDonViTinh nvarchar(50)
)
as
 insert into CongThucMenu values (@STTMenu,@STTHangHoa,@SoLuong,@TenDonViTinh)

Create proc proc_insertGoiMon
(
 @BanSo int,
 @STTMenu int,
 @SoLuong int
)
as
 insert into GoiMon values (@BanSo,@STTMenu,@SoLuong)

Create proc proc_insertTaiKhoan
(
 @TenTaiKhoan nvarchar(50),
 @MatKhau nvarchar(50),
 @Quyen nvarchar(9)
)
as
begin
 insert into TaiKhoan values (@TenTaiKhoan,@Quyen)
 exec ..sp_addlogin @TenTaiKhoan,@MatKhau,'QuanLyCaPhe'
 exec ..sp_adduser @TenTaiKhoan
 if (@Quyen = N'Chủ quán')
	exec proc_grantAllTable @TenTaiKhoan
end

Create proc proc_insertHoaDon
(
 @BanSo int,
 @ThoiGian Datetime,
 @PhuThu int,
 @ThanhTien int,
 @STTTaiKhoan int
)
as
 insert into HoaDon values (@BanSo,@ThoiGian,@PhuThu,@ThanhTien,@STTTaiKhoan)

Create proc proc_insertChiTietHoaDon
(
 @BanSo int,
 @ThoiGian Datetime,
 @STTMenu int,
 @SoLuong int,
 @DonGia int,
 @DonViTinh nvarchar(50)
)
as
 insert into ChiTietHoaDon values (@BanSo,@ThoiGian,@STTMenu,@SoLuong,@DonGia,@DonViTinh)

Create proc proc_insertThongKeTonKho
(
 @Thang DateTime,
 @TenHangHoa nvarchar(50),
 @SoLuong float,
 @TenDonViTinh nvarchar(50)
)
as
 insert into ThongKeTonKho values (@Thang,@TenHangHoa,@SoLuong,@TenDonViTinh)

Create proc proc_insertLogBackUp
(
 @ThoiGian Datetime,
 @TenTaiKhoan nvarchar(50),
 @TenBang varchar(13),
 @TacVu bit,
 @DuLieuGoc ntext,
 @DuLieuThayDoi ntext,
 @GhiChu ntext
)
as
 insert into LogBackUp values (@ThoiGian,@TenTaiKhoan,@TenBang,@TacVu,@DuLieuGoc,@DuLieuThayDoi,@GhiChu)